<template>
  <div class="table" >
    <!--表格主体-->
    <el-table
      id="iTable"
      v-loading.iTable="options.loading"
      :data="list.slice((currentPage-1)*pageSize,currentPage*pageSize)"
      :stripe="options.stripe"
      ref="mutipleTable"
      @selection-change="handleSelectionChange">
      <!--region 选择框-->
      <el-table-column v-if="options.mutiSelect" type="selection" style="width: 55px;">
      </el-table-column>
      <!--endregion-->

      <!--region 数据列-->
      <template v-for="(column, index) in columns">
        <el-table-column :prop="column.prop"
                         :key='column.label'
                         :label="column.label"
                         :align="column.align"
                         :width="column.width">
          <template slot-scope="scope">
            <template v-if="!column.render">
              <template v-if="column.formatter">
                <span v-html="column.formatter(scope.row, column)"></span>
              </template>
              <template v-else>
                <span>{{scope.row[column.prop]}}</span>
              </template>
            </template>
            <template v-else>
              <expand-dom :column="column" :row="scope.row" :render="column.render" :index="index"></expand-dom>
            </template>
          </template>
        </el-table-column>
      </template>
      <!--endregion-->

      <!--region 按钮操作组-->
      <el-table-column ref="fixedColumn" label="操作" align="center" :width="operates.width" :fixed="operates.fixed"
                       v-if="operates.list.filter(_x=>_x.show === true).length > 0">
        <template slot-scope="scope">
          <div class="operate-group">
            <template v-for="(btn, key) in operates.list"
                      v-if="$store.state.userInfo.employeeLv!=='门店管理员'">
              <!--<div class="item" v-if="btn.show" :key='btn.id'>-->
              <el-button :type="btn.type" size="mini" :disabled="btn.disabled"
                         :plain="btn.plain" @click.native.prevent="btn.method(key,scope.row)">{{ btn.label }}
              </el-button>
              <!--</div>-->
            </template>
            <el-button size="mini" type="success"  v-if="$store.state.userInfo.employeeLv === '门店管理员'" @click="deil">查看</el-button>
          </div>
        </template>
      </el-table-column>
      <!--endregion-->
    </el-table>
    <!--表格的分页与下部的操作按钮-->
    <div class="tablePage">
      <button btnclass="del" btntext="删除"></button><!--删除按钮-->
      <button btnclass="derive" btntext="导出Excel表格"></button><!--导出到Excel表格按钮-->
      <el-pagination
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
        :current-page= 'currentPage'
        :page-sizes="[10, 20, 50, 100]"
        :page-size= 'pageSize'
        layout="total, sizes, prev, pager, next, jumper"
        :total="list.length">
      </el-pagination>
    </div>
    <!--查看详情-->
    <el-dialog title="查看详情" :visible.sync="dialogTableVisible">
      <el-table :data="gridData">
        <el-table-column property="name" label="类名" ></el-table-column>
        <el-table-column property="data" label="值"></el-table-column>
      </el-table>
    </el-dialog>
  </div>
</template>
<!--endregion-->
<script>
  export default {
    name: 'combination_table',
    props: {
      list: {
        type: Array,
        default: []
      }, // 数据列表
      columns: {
        type: Array,
        default: []
      }, // 需要展示的列 === prop：列数据对应的属性，label：列名，align：对齐方式，width：列宽
      operates: {}, // 操作按钮组 === label: 文本，type :类型（primary / success / warning / danger / info / text），show：是否显示，icon：按钮图标，plain：是否朴素按钮，disabled：是否禁用，method：回调方法
      options: {
        type: Object,
        default: {
          stripe: false, // 是否为斑马纹 table
          highlightCurrentRow: false // 是否要高亮当前行
        },
      } // table 表格的控制参数
    },
//组件
    components: {
      expandDom: {
        functional: true,
        props: {
          row: Object,
          render: Function,
          index: Number,
          column: {
            type: Object,
            default: null
          }
        },
        render: (h, ctx) => {
          const params = {
            row: ctx.props.row,
            index: ctx.props.index
          };
          if (ctx.props.column) params.column = ctx.props.column;
          return ctx.props.render(h, params)
        }
      }
    },
// 数据
    data () {
      return {
        dialogTableVisible:false,
        gridData:[],
        currentPage: 1,
        pageSize: 10,
        pageIndex: 1,
        multipleSelection: [] // 多行选中
      }
    },
    mounted () {
    },
    computed: {
    },
    methods: {
      // 查看
      deil(){
        this.dialogTableVisible=true;
        const that = this;
        this.$axiosx.get(`/api/back_login.ing`)
          .then(function (response) {
            console.log(response.data[0]);
            console.log(response.data.package_id);
            that.gridData = [
              {name:'组合ID',data:response.data[0].package_id},
              {name:'组合名字',data:response.data[0].package_name},
              {name:'组合价格',data:response.data[0].package_price},
              {name:'创建日期',data:response.data[0].create_date},
            ]
          }).catch(function (err) {
          console.log(err)
        })

      },
      // 多行选中
      handleSelectionChange (val) {
        this.multipleSelection = val
        this.$emit('handleSelectionChange', val)
      },
      // 显示 表格操作弹窗
      showActionTableDialog () {
        console.log(4444)
        this.$emit('handelAction')
      },
      handleSizeChange (val) {
        this.pageSize = val
      },
      handleCurrentChange (val) {
        this.currentPage = val
      }
    }
  }
</script>
<style scoped>
  .table{
    margin-top: -20px;
  }
  /*.tableHeader {*/
    /*width: 100%;*/
    /*color: white;*/
    /*background-color: #00838f;*/
    /*height: 40px;*/
    /*margin-bottom: 10px;*/
    /*font-weight: 700;*/
    /*font-size: 14px;*/
  /*}*/

  .tableHeader span {
    display: inline-block;
    height: 40px;
    line-height: 40px;
    margin-left: 20px;
  }

  .tableHeader button {
    color: white;
    float: right;
    margin-right: 20px;
  }

  .tableSearch {
    /*width: 100%;*/
    height: 40px;
    background-color: #fff;
    margin-bottom: 1px;
    padding-left: 20px;
    padding-right: 20px;
  }

  .tablePage {
    background-color: #fff;
    height: 40px;
    padding-top: 10px;
    padding-left: 20px;
    padding-right: 40px;
  }

  .el-pagination {
    float: right;
  }
</style>
